<?php


namespace Modules\Common\Entities;

use Modules\Common\Helpers\Traits\Models\Attribute;
use Modules\Common\Helpers\Traits\Models\Scope;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;

/**
 * App\Entities\Model
 *
 * @property-read mixed $avatar_url
 * @property-read mixed $business_license_img_url
 * @property-read mixed $cover_url
 * @property-read mixed $created_at
 * @property-read mixed $deed_img_url
 * @property-read mixed $icon_url
 * @property-read mixed $id_card_back_img_url
 * @property-read mixed $id_card_img_url
 * @property-read mixed $image_url
 * @property-read mixed $images_url
 * @property-read mixed $legal_person_id_card_back_img_url
 * @property-read mixed $legal_person_id_card_img_url
 * @property-read mixed $other_proof_img_url
 * @property-read mixed $photo_url
 * @property-read mixed $proof_of_skills_img_url
 * @property-read mixed $related_qualifications_img_url
 * @property-read mixed $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|Model createdAtAfter($date)
 * @method static \Illuminate\Database\Eloquent\Builder|Model createdAtBefore($date)
 * @method static \Illuminate\Database\Eloquent\Builder|Model createdAtBetween($start, $end)
 * @method static \Illuminate\Database\Eloquent\Builder|Model createdAtOfDay($data)
 * @method static \Illuminate\Database\Eloquent\Builder|Model newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Model newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Model query()
 * @method static \Illuminate\Database\Eloquent\Builder|Model reviewAtOfDay($data)
 * @method static \Illuminate\Database\Eloquent\Builder|Model serviceTimeAfter($date)
 * @method static \Illuminate\Database\Eloquent\Builder|Model serviceTimeBefore($date)
 * @method static \Illuminate\Database\Eloquent\Builder|Model serviceTimeBetween($start, $end)
 * @method static \Illuminate\Database\Eloquent\Builder|Model updatedAtAfter($date)
 * @method static \Illuminate\Database\Eloquent\Builder|Model updatedAtBefore($date)
 * @method static \Illuminate\Database\Eloquent\Builder|Model updatedAtBetween($start, $end)
 * @method static \Illuminate\Database\Eloquent\Builder|Model updatedAtOfDay($data)
 * @mixin \Eloquent
 */
class Model extends BaseModel {
    use HasFactory;
    use Scope;
    use Attribute;

    protected $guarded = ['id', 'created_at', 'updated_at', 'deleted_at', 'addressable_id', 'addressable_type'];
    // protected $hidden  = ['password', 'payment_password'];
    protected $casts   = [
        'is_hide'                    => 'bool',
        'images'                     => 'array',
        'enable_status'              => 'bool',
        'is_default'                 => 'bool',
        'reason'                     => 'string',
        'content'                    => 'string',
        'snapshot'                   => 'json',
        'related_client'             => 'json',
        'meta'                       => 'json',
        'amount'                     => 'double',
        'amount_sum'                 => 'float',
        'proof_of_skills_img'        => 'array',
        'other_proof_img'            => 'array',
        'deed_img'                   => 'array',
        'business_license_img'       => 'array',
        'related_qualifications_img' => 'array',
    ];

    public function getCreatedAtAttribute($key) {
        return date("Y-m-d H:i:s", strtotime($key));
    }

    public function getUpdatedAtAttribute($key) {
        return date("Y-m-d H:i:s", strtotime($key));
    }

    public static function getTableName() {
        return with(new static)->getTable();
    }

    public static function getMorphClassName() {
        return with(new static)->getMorphClass();
    }



    protected function serializeDate(DateTimeInterface $date) {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }
}
